<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="所属商家" prop="merchant.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择所属商家"
            labelName = 'merchantName'
            labelValue = 'id'
            :value = "inputForm.merchant.id"
            :limit="1"
            @getValue='(value) => {inputForm.merchant.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'merchantName',
              label: '商户名称'
            }
            ]"
            :searchs="[
            {
              prop: 'merchantName',
              label: '商户名称'
            }
            ]"
            dataListUrl="/invoice/merchant/yxfpMerchant/list"
            queryEntityUrl="/invoice/merchant/yxfpMerchant/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="所属客户" prop="customer.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择所属客户"
            labelName = 'realName'
            labelValue = 'id'
            :value = "inputForm.customer.id"
            :limit="1"
            @getValue='(value) => {inputForm.customer.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'realName',
              label: '真实名称'
            }
            ]"
            :searchs="[
            {
              prop: 'realName',
              label: '真实名称'
            }
            ]"
            dataListUrl="/invoice/customer/yxfpCustomer/list"
            queryEntityUrl="/invoice/customer/yxfpCustomer/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="开票名称" prop="invoiceName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.invoiceName" placeholder="请填写开票名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="发票税号" prop="taxNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.taxNo" placeholder="请填写发票税号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="企业地址" prop="address"
                :rules="[
                 ]">
              <el-input v-model="inputForm.address" placeholder="请填写企业地址"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="企业电话" prop="phone"
                :rules="[
                 ]">
              <el-input v-model="inputForm.phone" placeholder="请填写企业电话"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="开户银行" prop="bankNm"
                :rules="[
                 ]">
              <el-input v-model="inputForm.bankNm" placeholder="请填写开户银行"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="开户账号" prop="bankAccNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.bankAccNo" placeholder="请填写开户账号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="发票内容" prop="content"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.content" placeholder="请填写发票内容"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="开票金额" prop="txnAmt"
                :rules="[
                 ]">
              <el-input v-model="inputForm.txnAmt" placeholder="请填写开票金额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="邮箱地址" prop="email"
                :rules="[
                 ]">
              <el-input v-model="inputForm.email" placeholder="请填写邮箱地址"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="发票状态" prop="state"
                :rules="[
                 ]">
              <el-input v-model="inputForm.state" placeholder="请填写发票状态"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注" prop="memo"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.memo" placeholder="请填写备注"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import GridSelect from '@/components/gridSelect'
  import YxfpInvoiceService from '@/api/invoice/invoice/YxfpInvoiceService'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          merchant: {
            id: ''
          },
          customer: {
            id: ''
          },
          invoiceName: '',
          taxNo: '',
          address: '',
          phone: '',
          bankNm: '',
          bankAccNo: '',
          content: '',
          txnAmt: '',
          email: '',
          state: '',
          memo: ''
        }
      }
    },
    components: {
      GridSelect
    },
    yxfpInvoiceService: null,
    created () {
      this.yxfpInvoiceService = new YxfpInvoiceService()
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建 发票管理`
        } else if (method === 'edit') {
          this.title = '修改 发票管理'
        } else if (method === 'view') {
          this.title = '查看 发票管理'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.yxfpInvoiceService.queryById(this.inputForm.id).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.yxfpInvoiceService.save(this.inputForm).then(({data}) => {
              this.visible = false
              this.$message.success(data)
              this.$emit('refreshDataList')
              this.loading = false
            }).catch(() => {
              this.loading = false
            })
          }
        })
      }
    }
  }
</script>

  
